package com.java.struts.menu.service;

import com.java.struts.base.exception.BusinessException;
import com.java.struts.menu.dao.MenuinfoDao;
import com.java.struts.menu.entity.MenuinfoEntity;

import java.util.List;

public class MenuinfoService {

    private MenuinfoDao menuinfoDao=new MenuinfoDao();

    /**
     * 查询所有菜品
     * @return  listMenu
     */
    public List<MenuinfoEntity> listMenu(){
        List<MenuinfoEntity> listMenu=( List<MenuinfoEntity>) menuinfoDao.listMenu();
        if(listMenu.size()<1){
            throw  new BusinessException("没有查询到菜品");
        }
        return  listMenu;
    }

    /**
     * 指定菜品名称查询菜品
     * @param meid
     * @return
     */
    public MenuinfoEntity queryMenuMname(Integer  meid){
        MenuinfoEntity menuinfoEntity = menuinfoDao.queryMenuMname(meid);
        if(menuinfoEntity == null){
            throw  new BusinessException("没有查询该菜品");
        }
        return menuinfoEntity;
    }

    /**
     * 通过id删除菜品信息
     * @param muneId
     */
    public void deleteMenu(Integer muneId){
        menuinfoDao.deleteMenu(muneId);
    }

    /**
     * 添加菜品信息
     * @param menuinfo
     */
    public void addMenu(MenuinfoEntity menuinfo){
        if(menuinfo == null){
            throw  new BusinessException("请输入您要添加的菜品类型的详细信息");
        }
        menuinfoDao.addMenu(menuinfo);
    }
}
